package bb.lanxing.calc.calculator;

import bb.lanxing.util.DoubleBuffer;
import bb.lanxing.util.Log;

public class PTAltitudeCalc {
    final static private String TAG = "PTAltitudeCalc";
    private static final float ALTITUDE_NONE = -50000.0f;

    private int PLAN_B = 2;
    private int plan = 1;
    private DoubleBuffer pressureBuffer = new DoubleBuffer(5);
    private DoubleBuffer temperatureBuffer = new DoubleBuffer(5);
    private float realP0 = 0.0f;

    private float altitudeOffset = 0.0f;

    private float curAltitude = ALTITUDE_NONE;

    public float getAltitude(float f, float f2, float f3) {
        this.curAltitude = ((f3 + 273.15f) * (((float) Math.pow(f / f2, 0.19022256135940552d)) - 1.0f)) / 0.0065f;
        Log.v(TAG, "getAltitude, p0 = " + f + ", curAltitude = " + this.curAltitude);
        if (this.plan == this.PLAN_B) {
            this.curAltitude += this.altitudeOffset;
            Log.v(TAG, "getAltitude(Plan B), altitudeOffset = " + this.altitudeOffset + ", curAltitude = " + this.curAltitude);
        }
        float f4 = this.curAltitude;
        return f4;
    }

    public boolean isCalibrated() {
        return this.realP0 > 0.0f;
    }

    public void reset() {
        this.curAltitude = ALTITUDE_NONE;
        this.pressureBuffer.reset();
        this.temperatureBuffer.reset();
        this.realP0 = 0.0f;
        this.altitudeOffset = 0.0f;
    }
}
